<template>
	<!-- 瀑布流排版 -->
	<view class="" style="height: 100%;">
		<view class="waterfall">
				<uv-waterfall ref="waterfall"
					v-model="goodsList"
					:add-time="50"
					column-count="2"
					left-gap="10"
					right-gap="10"
					column-gap="8"
					column-width="40"
					@changeList="changeList"
					>
					<template v-slot:list1>
						<view>
							<view v-for="(item, index) in list1"
								:key="item.id"
								class="waterfall-item"
								@click="todetail(item.id)"
								>
								<view class="waterfall-item__image">
									<image v-if="item.hasVideo" src="https://image.hzwltb69.com/app/imgs/chat/live.gif" class="lives" mode=""></image>
<!--									<image :src="item.img" mode="widthFix">-</image> -->
								<uv-image :src="item.img" mode="widthFix" width="350rpx" >
									<template v-slot:loading>
									<image class="loadingLogo" src="https://image.hzwltb69.com/app/date/2023/lodingLogo.png" mode="widthFix" ></image>
									</template>
								</uv-image>
								</view>
								<view class="p-title">
									{{item.name}}
								</view>
								<view class="p-pirce">
									<view style="display: flex;justify-content: space-between;">
										<view><text style="font-size: 22rpx;">￥</text>{{ item.price }}</view>
										<!-- <span style="font-size: 22rpx;color: #999999;margin-left: 20rpx;">{{item.paySales}}人付款</span> -->
										<view style="justify-content: center;" class="cat">抢购</view>
									</view>
									<!-- <view class="cat" v-show="cart">
										<img src="https://image.hzwltb69.com/app/date/2023/cat.png" alt="">
									</view> -->
									<view class="flagWord" v-if="item.paySales != 0">回头客{{item.paySales}}</view>
								</view>
							</view>
						</view>
					</template>
					<template v-slot:list2>
						<view>
							<view v-for="(item, index) in list2"
								:key="item.id"
								class="waterfall-item"
								>
								<view @click="todetail(item.id)" class="waterfall-item__image">
									<image v-if="item.hasVideo" src="https://image.hzwltb69.com/app/imgs/chat/live.gif" class="lives" mode=""></image>
<!--									<image :src="item.img" mode="widthFix"></image>-->
								<uv-image :src="item.img" mode="widthFix" width="350rpx" >
									<template v-slot:loading>
									<image class="loadingLogo" src="https://image.hzwltb69.com/app/date/2023/lodingLogo.png" mode="widthFix" ></image>
									</template>
								</uv-image>
								</view>
									<view class="p-title">
										{{item.name}}
									</view>
<!-- 									<view class="butie-box">
										<view class="butie">
											补贴:{{((item.price-item.cost)*rebate/100).toFixed(2)}}元
										</view>
									</view> -->
									<view class="p-pirce">
										<view style="display: flex; justify-content: space-between;">
											<view><text style="font-size: 22rpx;">￥</text>{{item.price}}</view>
											<view class="cat">抢购</view>
										</view>
										<view class="cat" v-show="cart">
											<img src="https://image.hzwltb69.com/app/date/2023/cat.png" alt="">
										</view>
									</view>
							</view>
						</view>
					</template>
				</uv-waterfall>
			</view>
	</view>
</template>

<script>
	export default{
		methods:{
			changeList(e){
				this[e.name].push(e.value);
			},
			todetail(e){
				this.$Router.push({
					path: '/pages/goods/detail',
					query: {
						id: e,
					}
				})
			},
			hasUserGet() {
				let that = this;
				let api = ""
				// 购物车列表
				if(that.listType == 1) api = 'common.cartRecom'
				// 用户列表
				if(that.listType == 2) api = 'common.gerenRecom'
				that.$http(api, {
					page: that.page,
					size: 10
				}).then(res => {
					this.rebate = res.rebate
					if(res.productList.length > 0){
						if(that.goodsList.length == 0){
							that.goodsList = res.productList
						}else{
							that.goodsList = that.goodsList.concat(res.productList)
						}
					}
				});
			},
		},
		data(){
			return{
				goodsList:[],
				page: 0,
				list1: [],  // 瀑布流第一列数据
				list2: [],  // 瀑布流第二列数据
				rebate: 20, // 补贴
			}
		},
		created() {
			this.hasUserGet()
		},
		props:{
			listType:{
				type: Number
			},
			cart:{
				type: Boolean,
				default: true
			}
		}
	}
</script>

<style lang="scss" scoped>
	image{
		width: 350rpx !important;
	}
	.waterfall {
		background: #f6f6f6;
	}
	.waterfall-item {
		overflow: hidden;
		margin-top: 18rpx;
		border-radius:15rpx;
	}
	.waterfall-item {
		background: #fff;
		.p-title{
			padding: 10rpx;
			width: 350rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			font-size: 28rpx;
			font-weight: 600;
			color: #030303;
		}
		.p-pirce{
			padding: 10rpx 10rpx 20rpx;
			color: #000;
			font-weight: 600;
			font-size: 32rpx;
			.cat{
				width: 86rpx;
				height: 46rpx;
				color: rgba(255, 255, 255, 1);
				background-color: rgba(238, 38, 50, 1);
				border-radius: 32rpx;
				font-size: 22rpx;
				line-height: 46rpx;
				text-align: center;
			}
		}
		.butie-box{
			padding: 10rpx;
			.butie{
				// width: 100rpx;
				color: #db5235;
				height: 50rpx;
				line-height: 50rpx;
				font-size: 25rpx;
				display: inline-block;
				border: 1px solid #db5235;
				padding: 0 20rpx 0 20rpx;
				border-radius: 20rpx;
			}
		}
	}
	.waterfall-item__ft {
		padding: 20rpx;
		background: #fff;
		&__title {
			margin-bottom: 10rpx;
			line-height: 48rpx;
			font-weight: 700;
			.value {
				font-size: 32rpx;
				color: #303133;
			}
		}
		&__desc .value {
			font-size: 28rpx;
			color: #606266;
		}
		&__btn {
			padding: 10px 0;
		}
	}
	.lives{
		width: 40rpx !important;
		height: 40rpx !important;
		position: absolute;
		bottom: 20rpx;
		right: 20rpx;
		z-index: 10;
	}
	.waterfall-item__image{
		position: relative;
	}
	.flagWord{
		display: flex;
		color: #d0b18e;
		font-weight: 500;
		font-size: 24rpx;
		margin-top: 16rpx;
		padding: 10rpx 0 0;
		border-top: 1rpx solid #eeeded;
	}
</style>